﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter02
{
    public class PrimitiveType : ICodeListing
    {
        public string IntegerTypes { get; set; }

        public string FloatingTypes { get; set; }

        public string DecimalType { get; set; }

        public string LiteralValue { get; set; }

        public void CodeListing()
        {
            AssignLiteralValue();
            AssignDoudle();
            AssignDecimal();
            AssignExponentialNotation();
            AssignHexNumber();
            FormatHexNumber();
            RoundTripFormat();
            Console.WriteLine();
        }

        private void AssignLiteralValue()
        {
            Console.WriteLine(42);
            Console.WriteLine(1.618034);
        }

        private void AssignDoudle()
        {
            Console.WriteLine(1.61803398874989);
        }

        private void AssignDecimal()
        {
            Console.WriteLine(1.618033988749895m);
        }

        private void AssignExponentialNotation()
        {
            Console.WriteLine(6.023E23f);
        }

        private void AssignHexNumber()
        {
            Console.WriteLine(0x022a);
        }

        private void FormatHexNumber()
        {
            Console.WriteLine("0x{0:X}", 42);
        }

        private void RoundTripFormat()
        {
            var number = 1.618033988749895d;
            double result;
            string text;

            text = string.Format("{0}", number);
            result = double.Parse(text);
            Console.WriteLine("{0}: result != number", result != number);

            text = string.Format("{0:R}", number);
            result = double.Parse(text);
            Console.WriteLine("{0}: result == number", result == number);
        }
    }
}
